<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%><jsp:include page="../admin.jsp"></jsp:include>
<html>
<head>
<title>【${o.name}】编辑广告</title>
<jsp:include page="../../../inc/js.jsp"></jsp:include>
<jsp:include page="../../../inc/css.jsp"></jsp:include>
<script type="text/javascript">
	$(function() {
		$("#update").button().click(function() {
			var id=$("#id").val();
			if(id==''||id=='0')
				f.action='insertAdv.do';
			else
				f.action="updateAdv.do";
			$("#f").ajaxSubmit(function(data){
					var o = jQuery.parseJSON(data);
					if(o.success){
						clearApplication();
						alert('操作成功！');
					}
					else
						alert('操作失败！'+o.err);
			});
			
			return false;
		});
		$("#back").button().click(function() {
			window.location.href='advList.do';
			return false;
		});
		$.get("getSelect.do", {
			type : 'ad',
			index:'${o.type}'
		}, function(data) {
			$("select#type").append(data);
		});
		
		$("#file").button().click(function() {
			$("#imgDiv").dialog( {
				title : '上传照片',
				height : 300,
				width : 630,
				modal : true
			});
			return false;
		});
		$("#cancel").button().click(function() {
			$("#imgDiv").dialog('close');
			return false;
		});
		$("#upload").button().click(function() {
			$.ajaxFileUpload({
				url:'upload.do',
				secureuri:false,
				fileElementId:'inputfile',
				dataType: 'json',
				success: function (data, status){
					if(data.success){
						$("#img").val(data.url);
						alert("上传成功！");
						$("#imgDiv").dialog('close');
					}else{
						alert('上传失败！');
					}
				}
			});
			return false;
		});
		$.get("getSelect.do", {
			type : 'YN',
			index:'${o.enabled}'
		}, function(data) {
			$("select#enabled").append(data);
		});
	});
</script>
</head>
<body>
<form  id="f" method="post">
<input type="hidden" id="id" name="id" value="${o.id }">
<table>

	<tr>
		<td>名称：</td>
		<td><input type="text" id="name" name="name" value="${o.name}"></td>
	</tr>
	<tr>
		<td>图片：</td>
		<td><input type="text" id="img" name="img" value="${o.img}"
			class="long"> <button id="file">上传</button></td>
	</tr>
	<tr>
		<td>URL：</td>
		<td><input type="text" id="url" name="url" value="${o.url}"
			class="long"> </td>
	</tr>
	<tr>
		<td>位置：</td>
		<td><select id="type" name="type">
			<option value="">请选择</option>
		</select></td>
	</tr>
	<tr>
		<td>排序编号：</td>
		<td><input type="text" id="orderid" name="orderid"
			value="${o.orderid}"></td>
	</tr>
	<tr>
		<td>启用：</td>
		<td><select id="enabled" name="enabled"></select></td>
	</tr>
	<tr>
		<td colspan="2">
		<button id="update">保存</button>
		<button id="back">返回</button>
		</td>
	</tr>
</table>
</form>
<div id="imgDiv" style="display: none;">
<form action="upload.do" id="upload_form" enctype="multipart/form-data">
<input type="file" name="file" id="inputfile" value="浏览" /><br />
<button id="upload">上传</button>
<button id="cancel">关闭</button>
</form>
</div>
</body>
</html>



